package cn.suxiaoxiang.suwebverify.table;

import org.bukkit.plugin.java.JavaPlugin;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Corder-Suxiaoxiang
 * @date 2025/3/18 21:27
 */
public class DatabaseTable {
    private JavaPlugin plugin;
    // 构造函数，接收插件实例
    public DatabaseTable(JavaPlugin plugin) {
        this.plugin = plugin;
    }
    // 自动创建表格
    public void createPlayerTables(Connection connection) {
        try (Statement stmt = connection.createStatement()) {

            String createAdminTableSQL = "CREATE TABLE IF NOT EXISTS player (" +
                    "username TEXT PRIMARY KEY, " +
                    "password TEXT NOT NULL" + // 最后一个字段不需要逗号
                    ");";
            stmt.executeUpdate(createAdminTableSQL);
            plugin.getLogger().info("数据库[player]表格已创建或已存在！");

        } catch (SQLException e) {
            plugin.getLogger().severe("创建表格时发生错误：" + e.getMessage());
        }
    }
}
